package org.linlinjava.litemall.db.service;

import java.util.List;

import javax.annotation.Resource;

import com.github.yulichang.base.MPJBaseServiceImpl;
import org.linlinjava.litemall.db.dao.LitemallGoodsSpecificationMerchandiseMapper;
import org.linlinjava.litemall.db.dao.LumiereFormulaSpecificationsMapper;
import org.linlinjava.litemall.db.domain.LitemallGoodsSpecificationMerchandise;
import org.linlinjava.litemall.db.domain.LitemallGoodsSpecificationMerchandiseExample;
import org.linlinjava.litemall.db.domain.LumiereFormulaSpecifications;
import org.springframework.stereotype.Service;

@Service
public class LitemallGoodsSpecificationMerchandiseService extends MPJBaseServiceImpl<LitemallGoodsSpecificationMerchandiseMapper, LitemallGoodsSpecificationMerchandise> {
	
    @Resource
    private LitemallGoodsSpecificationMerchandiseMapper goodsSpecificationMerchandiseMapper;

    public List<LitemallGoodsSpecificationMerchandise> queryByGid(Integer goodsId) {
        LitemallGoodsSpecificationMerchandiseExample example = new LitemallGoodsSpecificationMerchandiseExample();
        example.or().andGoodsIdEqualTo(goodsId);
        return goodsSpecificationMerchandiseMapper.selectByExample(example);
    }
    
    public List<LitemallGoodsSpecificationMerchandise> queryBySpecid(Integer specId) {
    	LitemallGoodsSpecificationMerchandiseExample example = new LitemallGoodsSpecificationMerchandiseExample();
    	example.or().andGoodsSpecificationIdEqualTo(specId);
    	return goodsSpecificationMerchandiseMapper.selectByExample(example);
    }

    public List<LitemallGoodsSpecificationMerchandise> queryByGidAndSpecificationId(Integer goodsId,Integer specificationId) {
        LitemallGoodsSpecificationMerchandiseExample example = new LitemallGoodsSpecificationMerchandiseExample();
        example.or().andGoodsIdEqualTo(goodsId).andGoodsSpecificationIdEqualTo(specificationId);
        return goodsSpecificationMerchandiseMapper.selectByExample(example);
    }

    public LitemallGoodsSpecificationMerchandise findById(Integer id) {
        return goodsSpecificationMerchandiseMapper.selectByPrimaryKey(id);
    }

    public void deleteByGid(Integer gid) {
        LitemallGoodsSpecificationMerchandiseExample example = new LitemallGoodsSpecificationMerchandiseExample();
        example.or().andGoodsIdEqualTo(gid);
        goodsSpecificationMerchandiseMapper.deleteByExample(example);
    }
    
    public void deleteById(Integer id) {
    	goodsSpecificationMerchandiseMapper.deleteByPrimaryKey(id);
    }
    
    public void deleteBySpecId(Integer specId) {
    	LitemallGoodsSpecificationMerchandiseExample example = new LitemallGoodsSpecificationMerchandiseExample();
    	example.or().andGoodsSpecificationIdEqualTo(specId);
    	goodsSpecificationMerchandiseMapper.deleteByExample(example);
    }
    
    public void deleteBySpecIdAndNotInMerchandiseIds(Integer specId, List<Integer> merchandiseIds) {
    	LitemallGoodsSpecificationMerchandiseExample example = new LitemallGoodsSpecificationMerchandiseExample();
    	example.or().andGoodsSpecificationIdEqualTo(specId).andMerchandiseIdNotIn(merchandiseIds);
    	goodsSpecificationMerchandiseMapper.deleteByExample(example);
    }
    
    public LitemallGoodsSpecificationMerchandise queryBySpecidAndMerchandiseId(Integer specId, Integer merchandiseId) {
    	LitemallGoodsSpecificationMerchandiseExample example = new LitemallGoodsSpecificationMerchandiseExample();
    	example.or().andGoodsSpecificationIdEqualTo(specId).andMerchandiseIdEqualTo(merchandiseId);
    	return goodsSpecificationMerchandiseMapper.selectOneByExample(example);
    }

    public void add(LitemallGoodsSpecificationMerchandise goodsSpecificationMerchandise) {
    	goodsSpecificationMerchandiseMapper.insertSelective(goodsSpecificationMerchandise);
    }
    
    public void update(LitemallGoodsSpecificationMerchandise goodsSpecificationMerchandise) {
    	goodsSpecificationMerchandiseMapper.updateByPrimaryKeySelective(goodsSpecificationMerchandise);
    }

}
